<template>
  <div class="app-container">
    <uc-table url="system/apk/versionPageQuery" name="版本管理" ref="userTable" pageable table-border :search-form="searchForm"
              @selection-change="handleSelectionChange">
      <template slot="searchForm">
        <el-form size="mini" :inline="true" :model="searchForm" class="demo-form-inline filter-container">
          <!--搜索输入框-->
          <el-form-item>
            <el-input type="text" v-model="searchForm.appKey" placeholder="请输唯一号" clearable
                      @clear="clearInput()"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" class="filter-item" @click="handleSearch()">查询</el-button>
            <el-button type="success" icon="el-icon-plus" class="filter-item" @click="handleAdd()">新 增</el-button>
          </el-form-item>
        </el-form>
      </template>
      <template slot="columns">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column prop="appKey" label="唯一号" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="versionName" label="版本名" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="apkSize" label="应用大小" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="updateStatus" label="是否强制更新" align="left"
                         :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="uploadTime" label="发布日期" align="left" show-overflow-tooltip></el-table-column>
        <el-table-column prop="modifyContent" label="更新内容" align="left"></el-table-column>
        <el-table-column prop="address" label="操作" width="220" align="left" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <!--编辑按钮-->
            <el-button size="mini" icon="el-icon-info" type="success" @click="handleInfo(scope.row)">详情</el-button>
            <el-button size="mini" type="danger" icon="el-icon-delete" :loading="deleteLoading"
                       @click="handleDelete(scope.row)">删除
            </el-button>
          </template>
        </el-table-column>
      </template>
    </uc-table>
  </div>
</template>
<script>
import UcTable from "@/components/UcTable/index.vue";
import {deleteData} from "@/api/apk";

export default {
  name: "userList",
  components: {UcTable},
  data() {
    return {
      searchForm: {
        deleted: false,

      },
      deleteLoading: false,
      enterpriseDominantList: [],
      checkOpen: false
    }
  },
  created() {
  },
  methods: {
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
    },
    handleSearch() {
      this.$refs.userTable.getTableData(1)
    },
    handleAdd() {
      this.$router.push("/sys/apkedit/0")
    },
    handleEdit(val) {
      this.$router.push("/sys/apkedit/" + val.versionId)
    },
    handleInfo(val) {
      this.$router.push("/sys/apkinfo/" + val.versionId)
    },
    clearInput() {
      //清除输入框
      this.searchForm.name = null
      this.handleSearch()
    },
    handleDelete(val) {
      this.$confirm('您确定要执行删除' + val.versionName + '这个版本吗？', '提醒信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteLoading = true
        deleteData(val).then(res => {
          this.deleteLoading = false
          this.$notify.success({
            title: '成功',
            message: "删除成功"
          })
          this.handleSearch()
        }).catch(res => {
          this.deleteLoading = false
          this.$notify.error({
            title: '失败',
            message: res.msg
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  }
}
</script>

<style scoped>

</style>
